﻿using System.Collections.Generic;
using AbstractBugTracker;

namespace Engine
{
    public sealed class CloseEngine<TBug, TBugDef>
        where TBug : class, IBug
        where TBugDef : BugDef
    {
        private readonly IBugTracker<TBug, TBugDef> m_BugTracker;
        private readonly string m_SearchPrefix;
        private readonly HashSet<string> m_Searches;

        public CloseEngine(
            IBugTracker<TBug, TBugDef> bugTracker,
            string searchPrefix,
            HashSet<string> searches)
        {
            m_BugTracker = bugTracker;
            m_SearchPrefix = searchPrefix;
            m_Searches = searches;
        }

        public void CloseReportsInBugTracker()
        {
            foreach (string search in m_Searches)
            {
                foreach (TBug bug in m_BugTracker.Search(m_SearchPrefix + search))
                {
                    bug.Close();
                }
            }
        }
    }
}
